package com.SmartCare.service.impl.moments;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.SmartCare.common.Result;
import com.SmartCare.common.dto.moments.ForwardInfoDTO;
import com.SmartCare.mapper.momments.ForwardInfoMapper;
import com.SmartCare.pojo.moments.ForwardInfo;
import com.SmartCare.service.moments.ForwardInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class ForwardInfoServiceImpl extends ServiceImpl<ForwardInfoMapper, ForwardInfo> implements ForwardInfoService {
    //转发动态
    @Override
    public Result forwardDynamic(ForwardInfoDTO forward) {
        ForwardInfo info = new ForwardInfo();
        BeanUtils.copyProperties(forward,info);
        boolean res = save(info);
        if (res){
            LambdaQueryWrapper<ForwardInfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ForwardInfo::getUserId,forward.getUserId());
            wrapper.eq(ForwardInfo::getDynamicId,forward.getDynamicId());
            wrapper.eq(ForwardInfo::getContent,forward.getContent());
            ForwardInfo one = getOne(wrapper);
            Map<String ,Long> map=new HashMap<>();
            map.put("id",one.getId());
            return Result.success("转发成功",map);
        }
        return Result.error("转发失败");
    }

    //取消转发
    @Override
    public Result deleteForward(Long id) {
        boolean res = removeById(id);
        if(res){
            return Result.success("取消转发成功");
        }
        return Result.error("取消转发失败");
    }

}
